package labox.innovation.gameserver.network.clientpackets;

import labox.innovation.gameserver.datatables.SkillTable;
import labox.innovation.gameserver.model.L2ShortCut;
import labox.innovation.gameserver.model.L2Skill;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

/**
 * This class ...
 * 
 * @version $Revision: 1.3.4.3 $ $Date: 2005/03/27 15:29:30 $
 */
public final class RequestShortCutReg extends L2GameClientPacket {

	private static final String _C__33_REQUESTSHORTCUTREG = "[C] 33 RequestShortCutReg";

	class ShortCut {

		public int _type;

		public long _id;

		public int _slot;

		ShortCut(int type, int slot, long id) {
			_type = type;
			_id = id;
			_slot = slot;
		}
	}

	private ShortCut[] _shortCuts;

	@Override
	protected void readImpl() {
		int size = readByte();
		if (size <= 0)
			return;
		_shortCuts = new ShortCut[size];
		for (int i = -1; ++i < _shortCuts.length;) {
			_shortCuts[i] = new ShortCut(readByte(), readByte(), readLong());
		}
	}

	@Override
	protected void runImpl() {
		FuzePcInstance activeChar = getClient().getActiveChar();
		if (activeChar == null)
			return;
		if (_shortCuts == null)
			return;
		for (int i = -1; ++i < _shortCuts.length;) {
			ShortCut sc = _shortCuts[i];
			//如果类型小于0，则标示删除
			if (sc._type < 0) {
				activeChar.deleteShortCut(sc._slot, false);
				continue;
			}
			//如果类型是技能检查是否拥有这个技能，以及是否为被动技能
			if (sc._type == L2ShortCut.TYPE_SKILL) {
				L2Skill skill = activeChar.getSkill((int) sc._id);
				if (skill == null || skill.isPassive())
					continue;
			}
			L2ShortCut lsc = activeChar.getShortCut(sc._slot);
			if (lsc == null) {
				activeChar.registerShortCut(new L2ShortCut(sc._slot, sc._type, sc._id));
			} else {
				lsc.setType(sc._type);
				lsc.setId(sc._id);
			}
		}

	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.clientpackets.ClientBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _C__33_REQUESTSHORTCUTREG;
	}
}
